package main;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.font.TextAttribute;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map;

import entity.item.Item;

public class Inventory 
{
	private ArrayList<Item> items;
	private final int HORIZ_OFFSET = 850, VERT_OFFSET = 150;
	
	public Inventory()
	{
		items = new ArrayList<Item>();
	}
	public void draw(Graphics2D g)
	{
		//draw the label
		Font old = g.getFont();
		Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
		map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
		map.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
		map.put(TextAttribute.SIZE, 22);
		map.put(TextAttribute.FONT, old.getFontName());
		g.setColor(Color.white);
		g.setFont(new Font(map));
		g.drawString("Inventory", HORIZ_OFFSET+7, VERT_OFFSET);
		g.setFont(old);
		g.setColor(Color.black);
		for (Item i : items)
		{
			i.draw(g);
		}
	}
	public void add(Item item)
	{
		//set the new item position to place it in the inventory screen
		int x = items.size()%2 * 100 + HORIZ_OFFSET;
		int y = items.size()/2 * 64 + VERT_OFFSET+40;
		item.setPosition(x, y);
		item.setInventory(this);
		items.add(item);
	}
	//checks if the inventory contains the item
	public boolean contains(Item item)
	{
		return items.contains(item);
	}
	public void remove(Item item)
	{
		items.remove(item);
	}
}
